const path = require('path')

const webpack = require('webpack')

const VueLoaderPlugin = require('vue-loader/lib/plugin')

const { CleanWebpackPlugin } = require('clean-webpack-plugin')

const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    mode: 'development',
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    devServer: { contentBase: './dist', open: true, hot: true, port: 3000 },
    plugins: [
        new htmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html') //指定渲染模板文件
        }),
        new VueLoaderPlugin(),
        new CleanWebpackPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    module: {
        rules: [{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        },
        {
            test: /\.styl(us)?$/,
            use: ['vue-style-loader', 'css-loader', 'postcss-loader', 'stylus-loader']
        },
        // {test:/\.sass$/,use:['style-loader','css-loader','sass-loader']},
        {
            test: /\.(jpg|png|svg|jpeg)$/,
            loader: 'url-loader',
            options: {
                name: '[hash:8]-[name].[ext]',
                limit: 8 * 1024
            }
        },
        {
            test: /\.(ttf|eot|svg|soff|woff2)$/,
            loader: 'file-loader'
        },
        {
            test: /\.js$/,
            use: 'babel-loader',
            exclude: /node_modules/
        },
        {
            test: /\.vue$/,
            use: 'vue-loader'
        }
        ]
    },
    resolve: {
        alias: {
            'vue': 'vue/dist/vue.js',
            '@': path.resolve(__dirname, './src'),
            'styles': path.resolve(__dirname, './src/assets/styles')
        }
    }
}